package com.huayun.netutil;

/**
 * Description:
 * <p>
 * 该类是作为网络请求的一些配置类，外部设置类似以下形式
 * NetInit.getInstance().setBuilder(new NetInit.Builder().setLoadingViewDelayed(2000));
 * <p>
 * <p>
 * Created on 2018/11/27 0027 16:58:24
 * author:Ahuangshang
 */
////////////////////////////////////////////////////////////////////
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//                  佛祖保佑       永不宕机     永无BUG             //
////////////////////////////////////////////////////////////////////
public class NetInit {
    private int LOADING_VIEW_DELAYED = 1000;//加载框延迟消失的时间
    private int SHOW_NET_PROGRESS_DIALOG = 0x9999;//加载框显示的eventID
    private int HIDE_NET_PROGRESS_DIALOG = 0x9998;//加载框消失的eventID
    private int DEFAULT_CONNECT_TIMEOUT = 15;//连接超时时间
    private int DEFAULT_READ_TIMEOUT = 10;//读取超时时间
    private int DEFAULT_WRITE_TIMEOUT = 10;//写入超时时间
    private boolean USE_JSON_REQUEST = false;//是否使用json请求数据,默认为false
    private String BASE_URL = "";//请求的baseUrl

    private NetInit() {
        this(new Builder());
    }

    private NetInit(Builder builder) {
        initData(builder);
    }

    private void initData(Builder builder) {
        this.LOADING_VIEW_DELAYED = builder.LOADING_VIEW_DELAYED;
        this.SHOW_NET_PROGRESS_DIALOG = builder.SHOW_NET_PROGRESS_DIALOG;
        this.HIDE_NET_PROGRESS_DIALOG = builder.HIDE_NET_PROGRESS_DIALOG;
        this.DEFAULT_CONNECT_TIMEOUT = builder.DEFAULT_CONNECT_TIMEOUT;
        this.DEFAULT_READ_TIMEOUT = builder.DEFAULT_READ_TIMEOUT;
        this.DEFAULT_WRITE_TIMEOUT = builder.DEFAULT_WRITE_TIMEOUT;
        this.USE_JSON_REQUEST = builder.USE_JSON_REQUEST;
        this.BASE_URL = builder.BASE_URL;
    }

    private static class SingletonHolder {
        private static NetInit instance = new NetInit();
    }

    public static NetInit getInstance() {
        return SingletonHolder.instance;
    }

    public void setBuilder(Builder builder) {
        initData(builder);
    }

    public int getLOADING_VIEW_DELAYED() {
        return LOADING_VIEW_DELAYED;
    }

    public void setLOADING_VIEW_DELAYED(int LOADING_VIEW_DELAYED) {
        this.LOADING_VIEW_DELAYED = LOADING_VIEW_DELAYED;
    }

    public int getSHOW_NET_PROGRESS_DIALOG() {
        return SHOW_NET_PROGRESS_DIALOG;
    }

    public void setSHOW_NET_PROGRESS_DIALOG(int SHOW_NET_PROGRESS_DIALOG) {
        this.SHOW_NET_PROGRESS_DIALOG = SHOW_NET_PROGRESS_DIALOG;
    }

    public int getHIDE_NET_PROGRESS_DIALOG() {
        return HIDE_NET_PROGRESS_DIALOG;
    }

    public void setHIDE_NET_PROGRESS_DIALOG(int HIDE_NET_PROGRESS_DIALOG) {
        this.HIDE_NET_PROGRESS_DIALOG = HIDE_NET_PROGRESS_DIALOG;
    }

    public int getDEFAULT_CONNECT_TIMEOUT() {
        return DEFAULT_CONNECT_TIMEOUT;
    }

    public void setDEFAULT_CONNECT_TIMEOUT(int DEFAULT_CONNECT_TIMEOUT) {
        this.DEFAULT_CONNECT_TIMEOUT = DEFAULT_CONNECT_TIMEOUT;
    }

    public int getDEFAULT_READ_TIMEOUT() {
        return DEFAULT_READ_TIMEOUT;
    }

    public void setDEFAULT_READ_TIMEOUT(int DEFAULT_READ_TIMEOUT) {
        this.DEFAULT_READ_TIMEOUT = DEFAULT_READ_TIMEOUT;
    }

    public int getDEFAULT_WRITE_TIMEOUT() {
        return DEFAULT_WRITE_TIMEOUT;
    }

    public void setDEFAULT_WRITE_TIMEOUT(int DEFAULT_WRITE_TIMEOUT) {
        this.DEFAULT_WRITE_TIMEOUT = DEFAULT_WRITE_TIMEOUT;
    }

    public boolean isUSE_JSON_REQUEST() {
        return USE_JSON_REQUEST;
    }

    public void setUSE_JSON_REQUEST(boolean USE_JSON_REQUEST) {
        this.USE_JSON_REQUEST = USE_JSON_REQUEST;
    }

    public String getBASE_URL() {
        return BASE_URL;
    }

    public void setBASE_URL(String BASE_URL) {
        this.BASE_URL = BASE_URL;
    }

    public static class Builder {
        int LOADING_VIEW_DELAYED = 1000;//加载框延迟消失的时间
        int SHOW_NET_PROGRESS_DIALOG = 0x9999;//加载框显示的eventID
        int HIDE_NET_PROGRESS_DIALOG = 0x9998;//加载框消失的eventID
        private int DEFAULT_CONNECT_TIMEOUT = 15;//连接超时时间
        private int DEFAULT_READ_TIMEOUT = 10;//读取超时时间
        private int DEFAULT_WRITE_TIMEOUT = 10;//写入超时时间
        private boolean USE_JSON_REQUEST = false;//是否使用json请求数据,默认为false
        private String BASE_URL = "";//请求的baseUrl

        public Builder() {
        }

        public Builder setLoadingViewDelayed(int loadingViewDelayed) {
            LOADING_VIEW_DELAYED = loadingViewDelayed;
            return this;
        }

        public Builder setShowNetProgressDialog(int showNetProgressDialog) {
            SHOW_NET_PROGRESS_DIALOG = showNetProgressDialog;
            return this;
        }

        public Builder setHideNetProgressDialog(int hideNetProgressDialog) {
            HIDE_NET_PROGRESS_DIALOG = hideNetProgressDialog;
            return this;
        }

        public Builder setDEFAULT_CONNECT_TIMEOUT(int DEFAULT_CONNECT_TIMEOUT) {
            this.DEFAULT_CONNECT_TIMEOUT = DEFAULT_CONNECT_TIMEOUT;
            return this;
        }

        public Builder setDEFAULT_READ_TIMEOUT(int DEFAULT_READ_TIMEOUT) {
            this.DEFAULT_READ_TIMEOUT = DEFAULT_READ_TIMEOUT;
            return this;
        }

        public Builder setDEFAULT_WRITE_TIMEOUT(int DEFAULT_WRITE_TIMEOUT) {
            this.DEFAULT_WRITE_TIMEOUT = DEFAULT_WRITE_TIMEOUT;
            return this;
        }

        public Builder setUSE_JSON_REQUEST(boolean USE_JSON_REQUEST) {
            this.USE_JSON_REQUEST = USE_JSON_REQUEST;
            return this;
        }

        public Builder setBASE_URL(String BASE_URL) {
            this.BASE_URL = BASE_URL;
            return this;
        }

        public String getBASE_URL() {
            return BASE_URL;
        }


        public boolean isUSE_JSON_REQUEST() {
            return USE_JSON_REQUEST;
        }

        public int getDEFAULT_CONNECT_TIMEOUT() {
            return DEFAULT_CONNECT_TIMEOUT;
        }

        public int getDEFAULT_READ_TIMEOUT() {
            return DEFAULT_READ_TIMEOUT;
        }

        public int getDEFAULT_WRITE_TIMEOUT() {
            return DEFAULT_WRITE_TIMEOUT;
        }

        public int getLOADING_VIEW_DELAYED() {
            return LOADING_VIEW_DELAYED;
        }

        public int getSHOW_NET_PROGRESS_DIALOG() {
            return SHOW_NET_PROGRESS_DIALOG;
        }

        public int getHIDE_NET_PROGRESS_DIALOG() {
            return HIDE_NET_PROGRESS_DIALOG;
        }
    }

}
